package com.enrollandpay.web;

import com.enrollandpay.base.BaseController;
import com.enrollandpay.model.Activity;
import com.enrollandpay.model.Campus;
import com.enrollandpay.model.Signup;
import com.enrollandpay.service.*;
import com.enrollandpay.utils.DateUtil;
import com.enrollandpay.utils.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by 94504 on 2017/6/28.
 */
@Controller
@RequestMapping("/signup")
public class SignupController
{
    @Autowired
    private SignupService signupService;
    @Autowired
    private ActivityService activityService;
    @Autowired
    private CampusService campusService;
    @Autowired
    private ClazzService clazzService;
    @Autowired
    private SchoolService schoolService;
    @Autowired
    private GradeService gradeService;
    @Autowired
    private StudentService studentService;
    @Autowired
    private UserService userService;


    @RequestMapping("/gotoSignupPage")
    public String gotoSignupPage(HttpServletRequest request)
    {
        request.setAttribute("schools", schoolService.selectAll());
        request.setAttribute("campuses", campusService.selectAll());
        request.setAttribute("grades", gradeService.selectAll());
        request.setAttribute("clazzs", clazzService.selectAll());
        request.setAttribute("students", studentService.selectAll());

        return "main/signup";
    }

    @RequestMapping("/selectSignup")
    @ResponseBody
    public List<Signup> selectSignup(Signup signup)
    {
        //List<Signup> list = signupService.selectSignup(signup);
        return signupService.selectSignup(signup);
    }

    @RequestMapping("/gotoSignupSavePage")
    public String gotoSignupSavePage(Integer id, Model model)
    {
        model.addAttribute("activities", activityService.selectAll());
        if(id != null)
            model.addAttribute("thisSignup", signupService.selectByPrimaryKey(id));

        return "save/signup_save";
    }

    @RequestMapping("/deleteSignupByPrimaryKey")
    @ResponseBody
    public ResultJson deleteSignupByPrimaryKey(Integer primaryKey)
    {
        if(primaryKey != null)
            signupService.deleteByPrimaryKey(primaryKey);

        return new ResultJson();
    }


    /**
     * 根据param删除对应的数据
     * @param separatorChar
     *         分割符
     */
    @RequestMapping("/deleteSignupsByPK")
    @ResponseBody
    public ResultJson deleteSignupsByPK(String pkStr, Character separatorChar)
    {
        return signupService.deleteEntitiesByPK(pkStr, separatorChar);
    }
}
